/*
 * @Author: 张安 3416820388@qq.com
 * @Date: 2023-01-14 09:14:00
 * @LastEditors: 张安 3416820388@qq.com
 * @LastEditTime: 2023-01-14 11:09:52
 * @FilePath: \rustTest\sunlist.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include<stdio.h>
#include<stdlib.h>
#include <stdbool.h>
#include <math.h>
//增加math库之后编译时后面要加上-lm
//gcc sunlist.c -o sunlist -lm
#define GETBIT(x,n)   ((x) >> (n)&1)

int cmp ( const void *a , const void *b )
{
    return *(int *)a - *(int *)b;
}


//有序数组去重
int removeDuplicates(int* nums, int numsSize){
    if(numsSize==0)
        return 0;
    int fast=1,slow=1;
    while(fast<numsSize){
        if(nums[fast]!=nums[fast-1]){
            nums[slow]=nums[fast];
            slow++;
        }
        fast++;
    }
    return slow;
}


void listSun(int *nums,int numsSize){
    //排序
    qsort(nums,numsSize,sizeof(int),cmp);
    //去重
    int size = removeDuplicates(nums,numsSize);
    for(int i=0;i<size;i++){
        printf("%d\t",nums[i]);
    }
    int n= pow(2,size);
    for(int i = 0;i<n;i++){
        printf("%d->[",i);
        for(int j = 0;j<32;j++){
            int m = GETBIT(i,j);
            if(m == 1){
                printf("%d ",nums[j]);
            }
        }
        printf("]\r\n");
    }
}

int main(){
    int nums[] = {1,1,2,3,5,79,5,32,1,3,7,6,452,5,6,5,5,5,56854658,6265,5,652,85,26,2,5};
    listSun(nums,26);
    return 0;
}